﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FileSystem.Services.Realization;
using FileSystem.ViewModels;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using System = FileSystem.Services.Realization.System;

namespace FileSystem.Views
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class FileSystemPage : ContentPage
    {
        public FileSystemPage()
        {
            InitializeComponent();
        }

        private async void MenuItem_OnClicked(object sender, EventArgs e) {
            UserStorage userStorage = new UserStorage(new PreferenceStorage());
            RootDirItemStorage rootDirItemStorage = new RootDirItemStorage(new PreferenceStorage());
            DirItemStorage dirItemStorage = new DirItemStorage(new PreferenceStorage());
            PhysicalDiskBlockStorage physicalDiskBlockStorage = new PhysicalDiskBlockStorage(new PreferenceStorage());
            DiskBlockStorage diskBlockStorage = new DiskBlockStorage(new PreferenceStorage());
            AccessControlInfoStorage accessControlInfoStorage = new AccessControlInfoStorage(new PreferenceStorage());
            Services.Realization.System system = new Services.Realization.System(userStorage, rootDirItemStorage, dirItemStorage, physicalDiskBlockStorage, diskBlockStorage, accessControlInfoStorage);

            //DirItemViewModel dirItemViewModel = sender as;
            // The sender is the menuItem
            var menuItem = sender as MenuItem;

            DirItemViewModel dirItemViewModel = menuItem.BindingContext as DirItemViewModel;

            var dirItem = dirItemViewModel.DirItem;

            await system.Delete(dirItem.DirItemName,dirItem.Location );

            ViewModelLocator viewModelLocator = Application.Current.Resources["ViewModelLocator"] as ViewModelLocator;

            viewModelLocator.FileSystemPageViewModel.DirItems.Remove(
                dirItemViewModel);
        }
    }
}